package com.dgut.admin.controller;

import com.dgut.admin.param.NoticeAddParam;
import com.dgut.admin.param.NoticeModifyParam;
import com.dgut.admin.service.AdminUserService;
import com.dgut.admin.service.NoticeService;
import com.dgut.common.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author zyq
 * @Date 2022/4/8 11:32
 * @Description TODO
 * @Version 1.0
 **/
@RequestMapping("/api/admin/notice")
@RestController
public class NoticeController {

    private final NoticeService noticeService;

    public NoticeController(NoticeService noticeService) {
        this.noticeService = noticeService;
    }

    /**
     * 添加公告
     */
    @PostMapping
    public R addNotice(@RequestBody @Valid NoticeAddParam param) {
        noticeService.addNotice(param);
        return R.ok();
    }

    /**
     * 公告列表
     */
    @GetMapping("/list")
    public R listNotice(Integer pageNum, Integer pageSize, Integer state) {
        return R.ok().data(noticeService.listNotice(pageNum, pageSize, state));
    }

    /**
     * 修改公告
     */
    @PutMapping
    public R modifyNotice(@RequestBody @Valid NoticeModifyParam param) {
        noticeService.modifyNotice(param);
        return R.ok();
    }

    /**
     * 删除公告
     */
    @DeleteMapping("/{id}")
    public R deleteNotice(@PathVariable("id") Integer id) {
        noticeService.deletedNotice(id);
        return R.ok();
    }



}
